import type { ReportColumnsItem } from '../types'

/** 获取最后一层 column */
export function getFlatternColumns(columns: ReportColumnsItem[]) {
  if (columns.every(v => !v.children || v.children.length === 0)) {
    return columns
  }
  return columns.reduce((acc, v) => {
    if (v.children) {
      acc = acc.concat(getFlatternColumns(v.children))
    }
    else {
      acc.push(v)
    }
    return acc
  }, [] as ReportColumnsItem[])
}
